package com.onec.service.im.handler;

import com.mysql.cj.protocol.ServerSession;
import com.onec.service.im.protocol.Im;
import com.onec.service.im.service.LoginProcesser;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 登录处理
 */
@Service
public class LoginRequestHandler extends ChannelInboundHandlerAdapter {

  @Autowired
  LoginProcesser loginProcesser;

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    if (null == msg || !(msg instanceof Im.Message)) {
      super.channelRead(ctx, msg);
      return;
    }
    Im.Message pkg = (Im.Message) msg;
    //取得请求类型
    Im.HeadType headType = pkg.getType();
    if (!headType.equals(loginProcesser.type())) {
      super.channelRead(ctx, msg);
      return;
    }
    //ServerSession session = new ServerSession(ctx.channel());



    super.channelRead(ctx, msg);
  }
}
